﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Odbc;
using Org.SqlHelper;

namespace QualityRpt.Dao.Db2
{
    public class UserDao:IUserDao
    {
        public DataRow Get(string loginname, string md5pass)
        {
            string sbText = "USERNAME='" + loginname + "' AND PASSWORD='"+md5pass+"'";
            DataTable rtTable = GetList(sbText, string.Empty);
            if (rtTable.Rows.Count > 0)
            {
                return rtTable.Rows[0];
            }
            return null;
        }
        public DataTable GetList(string where,string sort)
        {
            StringBuilder sbText = new StringBuilder();
            sbText.Append("SELECT * FROM RPT.LOGIN_INFO ");
            if (where.Trim() != string.Empty)
            {
                sbText.Append(" WHERE " + where);
            }
            if (sort.Trim() != string.Empty)
            {
                sbText.Append(" ORDER BY " + sort);
            }
            using (OdbcConnection conn = ODBCHelper.GetConnection())
            {
                return ODBCHelper.ReadTable(conn, CommandType.Text, sbText.ToString());
            }
        }
		public DataRow Get(int id){
			DataRow row = null;
			DataTable rtTable = GetList ("ID=" + id.ToString (), string.Empty);
			if (rtTable.Rows.Count > 0) {
				row = rtTable.Rows [0];
			}
			return row;
		}
    }
}
